<?php


// wird nicht mehr verwendet in database

require "../../system/framework.php";
//sqlAddTableField($_REQUEST['table'],$_REQUEST['field'],$_REQUEST['typ']);
//sqlAddTableField($_REQUEST['table'],$_REQUEST['field'],$_REQUEST['typ']);


//$tableName = $_REQUEST['table'];


//$fieldType = db::getValue("SELECT field_type FROM _field_type WHERE id='$fieldTypeId'");
$dbField=new table_field();  



$tableName=trim($_REQUEST['table_name']);


// Field Name auslesen
if (isset($_REQUEST['field_name'])) {
    $fieldName=trim($_REQUEST['field_name']);
    $dbField->fieldName=$fieldName;  
}


// Field Caption auslesen
if (isset($_REQUEST['field_caption'])) {
    $fieldCaption=trim($_REQUEST['field_caption']);
    $dbField->fieldCaption=$fieldCaption;  
}


// Field Type auslesen
$fieldType= request::generalRequest("field_type");
if (isset($_REQUEST['__field_type'])) {
    $fieldTypeId = $_REQUEST['__field_type'];
    $fieldType = db::getValue("SELECT field_type FROM _field_type WHERE id='{$fieldTypeId}'");
}



//$_REQUEST['field_type'];



//__field_type





/*      $fieldType="";
      if (isset($_REQUEST['type']))
          {
          $fieldType=$_REQUEST['type'];
          }  */

$required=0;

if (isset($_REQUEST['required']))
    {
    $required=1;
    }

$uniqueIndex=0;

if (isset($_REQUEST['unique_index']))
    {
    $uniqueIndex=1;
    }

$searchIndex=0;

if (isset($_REQUEST['search_index']))
    {
    $searchIndex=1;
    }

$errorMessage=0;

if (isset($_REQUEST['error_message']))
    {
    $errorMessage=$_REQUEST['error_message'];
    }

$joinField="";

if (isset($_REQUEST['join_field']))
    {
    $joinField=$_REQUEST['join_field'];
    }


    
$defaultValue="";
if (isset($_REQUEST['default_value']))
    {
    $defaultValue=$_REQUEST['default_value'];
    }    
    
    


$tableVisible = 0;
if (isset($_REQUEST['table_visible']))
    {
    $tableVisible=1;
    }


$formVisible = 0;
if (isset($_REQUEST['form_visible']))
    {
    $formVisible=1;
    }
    
    $detailVisible = 0;
if (isset($_REQUEST['detail_visible']))
    {
    $detailVisible=1;
    }






    
    
$index=0;


$dbField->tableName=$tableName;
//$dbField->fieldName = $fieldName;
//$dbField->fieldCaption=$fieldCaption;
$dbField->fieldType=$fieldType;

if ($fieldType == "image") {
    $dbField->imageResize = "100";
}


$dbField->required=$required;
$dbField->searchIndex=$searchIndex;
$dbField->uniqueIndex=$uniqueIndex;
$dbField->errorMessage=$errorMessage;
$dbField->joinField=$joinField;
$dbField->tableVisible = $tableVisible;
$dbField->formVisible = $formVisible;
$dbField->detailVisible = $detailVisible;
$dbField->defaultValue = $defaultValue;
$dbField->addTableField();

//, $_REQUEST['required']
//db::addTableField($_REQUEST['table'],$_REQUEST['field'],$fieldType);
$id=db::getValue("SELECT id FROM _table WHERE `table_name`='$tableName'");
$redirect="[php_property:action]";

//[id2] ersetzen
$redirect=str_ireplace("[form:id]", $id, $redirect);


//$table = sqlCreateTable($_REQUEST['table']);
//header("Location: [php_property:redirect]?table=$table");
http::redirect($redirect);


//print_r($_REQUEST);

//http::redirect("[php_property:redirect]?table=".$_REQUEST['table']);

//header("Location: [php_property:redirect]");

?>